package io.renren.modules.frt.service.impl;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.toolkit.StringUtils;

import io.renren.common.utils.MapUtils;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.frt.dao.TaskDao;
import io.renren.modules.frt.entity.TaskEntity;
import io.renren.modules.frt.service.TaskService;

@Service("taskService")
public class TaskServiceImpl extends ServiceImpl<TaskDao, TaskEntity> implements TaskService {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public PageUtils queryPage(Map<String, Object> params) {

		EntityWrapper ew = new EntityWrapper<TaskEntity>();
		if (params.get("sendStatus") != null) {
			ew.eq("send_status", params.get("sendStatus"));
		}
		ew.orderBy("create_time", false);
		
		String key = MapUtils.toStr(params, "key");
		if(StringUtils.isNotEmpty(key)) {
			ew.like("name", key);
		}

		Page<TaskEntity> page = this.selectPage(new Query<TaskEntity>(params).getPage(), ew);

		return new PageUtils(page);
	}

}
